package com.charles.seckillData.feignFallBack;

import com.charles.seckillComponentCommon.domain.R;
import com.charles.seckillData.feignService.RemoteAdminService;
import com.charles.seckillData.model.UserLogin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author Charles-H
 *
 * 负载均衡后台业务降级处理
 */
@Component
public class RemoteAdminServiceFallbackFactory implements FallbackFactory<RemoteAdminService> {

    private static final Logger LOGGER = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);
    
    @Override
    public RemoteAdminService create(Throwable cause) {
        
        LOGGER.error("后台服务调用失败:{}", cause.getMessage());
        
        return new RemoteAdminService() {
            @Override
            public R<UserLogin> queryUserDataByUserCard(String userCard, String source) {
                return R.fail("后台服务调用失败:{}" + cause.getMessage());
            }
        };
    }
}
